package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.example.mapper.MoneyTotalMapper;
import org.example.model.money.MoneyTotal;
import org.example.service.MoneyTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional
public class MoneyTotalServiceImpl extends ServiceImpl<MoneyTotalMapper, MoneyTotal> implements MoneyTotalService {

    @Autowired
    private MoneyTotalMapper moneyTotalMapper;

    @Override
    public Boolean UpdateMoney(MoneyTotal moneyTotal) {
        moneyTotal.setId(1);
        MoneyTotal total = moneyTotalMapper.selectById(1);
        moneyTotal.setMoney(total.getMoney() + moneyTotal.getMoney());
        return moneyTotalMapper.updateById(moneyTotal) > 0;
    }

    @Override
    public MoneyTotal GetAll() {
        return moneyTotalMapper.selectById(1);
    }
}
